<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>后台登录</title>
    <link rel="stylesheet" type="text/css" href="/static/admin/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="/static/admin/css/login.css"/>
</head>

<body>
    <div class="m-login-bg">
        <div class="m-login">
            <h3>后台系统登录</h3>
            <div class="m-login-warp">
                <form class="layui-form" method="post">
                    <div class="layui-form-item">
                        <input type="text" name="username" required lay-verify="required" placeholder="用户名"
                            autocomplete="off" class="layui-input" value="201820180215">
                    </div>
                    <div class="layui-form-item">
                        <input type="password" name="password" required lay-verify="required" placeholder="密码"
                            autocomplete="off" class="layui-input" value="123456">
                    </div>
                    <div class="layui-form-item m-login-btn">
                        <div class="layui-inline">
                            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="loginForm">登录</button>
                        </div>
                        <div class="layui-inline">
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
    </div>
</div>
<script src="/static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['jquery','form','layer'],function () {
        var form =layui.form(),
            layer = layui.layer,
            $ =layui.jquery;

        form.on('submit(loginForm)',function (data) {
            $.ajax({
                type:"POST",
                url:"/admin/user/login",
                data:{
                    username: data.field.username,
                    password: data.field.password
                },
                dataType:"json",
                success:function (res) {
                    if (res.flag){
                        window.location.href="/admin/user/index"
                    }else {
                        layer.msg(res.message)
                        $('input[name="username"]').val("");
                        $('input[name="password"]').val("");
                    }
                }
            })
            return false;
        })
    })
</script>
</body>

</html>
